const express = require('express')
const config = require('./config')
const httpSend = require('./middleware/httpSend')
const demonstration = require('./middleware/demonstration')
const errorSend = require('./middleware/errorSend')

const app = express()
// 处理响应
app.use(httpSend())


// 静态资源访问
app.use('/uploads', express.static(__dirname + '/uploads'))

// 全局中间件(跨域)
app.use(require('cors')())

// 演示数据处理
// app.use(demonstration())

app.use(express.json())
app.use(express.urlencoded({ extended: true }))

// 注册路由
require('./route/admin')(app)

// 处理错误的中间件
app.use(errorSend())

app.listen(config.port, () => {
  console.log(`http://localhost:${config.port}`)
});

